package jee.boot.module.oauth2.rest;

import jee.boot.common.basic.result.ResponseMessage;
import jee.boot.common.basic.result.Result;
import jee.boot.entity.auth.Account;
import jee.boot.module.oauth2.service.ValidateCodeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 验证码
 */
@RestController
@RequestMapping("/code")
public class ValidateCodeController {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ValidateCodeService validateCodeService;

    /**
     * 生成图片验证码
     *
     * @return
     */
    @GetMapping("/getImgCode")
    public ResponseMessage<Object> getImgCode() {
        Map<String, String> imgCode = validateCodeService.getImgCode();
        return Result.success(imgCode);
    }

    /**
     * 发送验证码(短信,邮件)
     * @return
     */
    @PostMapping("/sendCode")
    public ResponseMessage<Object> sendCode(@RequestBody Account account) {
        Map<String, String> sendCode = validateCodeService.sendCode(account);
        return Result.success(sendCode);
    }
}
